package models;

import android.text.format.Time;

/**
 * This is a class that wraps the android time object to make it comparable.  
 * 
 * @author Justin
 *
 */
public class TimeSortingWrapper implements Comparable<TimeSortingWrapper>{

	/**
	 * The wrapped time
	 */
	public Time time;
	
	/**
	 * Constructs a new TimeSortingWrapper containing time
	 * @param time
	 */
	public TimeSortingWrapper(Time time) {
		this.time = time;
	}
	
	/**
	 * 
	 * @param other the other TimeSortingWrapper to be compared to
	 * @return the difference in minutes between other and this's time objects
	 * i.e. other time minus this time.
	 */
	public int difference(TimeSortingWrapper other) {
	    return (int) (other.time.toMillis(false) - this.time.toMillis(false)) / (1000 * 60);
	}

	/**
	 * compareTo Function for comparable interface
	 * 
	 */
	public int compareTo(TimeSortingWrapper other) {
		return Time.compare(this.time, other.time);
	}
	
	@Override
	public boolean equals(Object o) {
		if (!(o instanceof TimeSortingWrapper)) {
			return false;
		} else {
			return this.compareTo( (TimeSortingWrapper) o) == 0;
		}
	}
	
	@Override
	public int hashCode() {
		return time.hashCode();
	}
}
